package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarInfoDetail;
import com.ruoyi.system.service.ICarInfoDetailService;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 吊车列Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
//@Anonymous
@RequestMapping("/system/detail")
public class CarInfoDetailController extends BaseController {
	@Autowired
	private ICarInfoDetailService carInfoDetailService;

	/**
	 * 查询吊车列列表
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:list')")
	@GetMapping("/list")
	public TableDataInfo list(CarInfoDetail carInfoDetail) {
		startPage();
		List<CarInfoDetail> list = carInfoDetailService.selectCarInfoDetailList(carInfoDetail);
		return getDataTable(list);
	}

	/**
	 * 导出吊车列列表
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:export')")
	@Log(title = "吊车列", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, CarInfoDetail carInfoDetail) {
		List<CarInfoDetail> list = carInfoDetailService.selectCarInfoDetailList(carInfoDetail);
		ExcelUtil<CarInfoDetail> util = new ExcelUtil<CarInfoDetail>(CarInfoDetail.class);
		util.exportExcel(response, list, "吊车列数据");
	}

	/**
	 * 获取吊车列详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return success(carInfoDetailService.selectCarInfoDetailById(id));
	}

	/**
	 * 新增吊车列
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:add')")
	@Log(title = "吊车列", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody CarInfoDetail carInfoDetail) {
		System.out.println(carInfoDetail.getCarNo());
		return toAjax(carInfoDetailService.insertCarInfoDetail(carInfoDetail));
	}

	/**
	 * 修改吊车列
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:edit')")
	@Log(title = "吊车列", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody CarInfoDetail carInfoDetail) {
		return toAjax(carInfoDetailService.updateCarInfoDetail(carInfoDetail));
	}

	/**
	 * 删除吊车列
	 */
	@PreAuthorize("@ss.hasPermi('system:detail:remove')")
	@Log(title = "吊车列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(carInfoDetailService.deleteCarInfoDetailByIds(ids));
	}

	@Log(title = "用户管理", businessType = BusinessType.IMPORT)
	@PostMapping("/importData")
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
		ExcelUtil<CarInfoDetail> util = new ExcelUtil<CarInfoDetail>(CarInfoDetail.class);
		List<CarInfoDetail> userList = util.importExcel(file.getInputStream());
//    	LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//    	String operName = loginUser.getUsername();
		String message = carInfoDetailService.importCarInfo(userList, updateSupport);
		return AjaxResult.success(message);
	}

	@PostMapping("/importTemplate")
	public void importTemplate(HttpServletResponse response) {
		ExcelUtil<CarInfoDetail> util = new ExcelUtil<CarInfoDetail>(CarInfoDetail.class);
		util.importTemplateExcel(response, "吊车数据");
	}
	
	/**
	 * 查询吊车列列表
	 */
	@PostMapping("/listOpen")
	public TableDataInfo listOpen(CarInfoDetail carInfoDetail) {
		startPage();
		List<CarInfoDetail> list = carInfoDetailService.selectCarInfoDetailList(carInfoDetail);
		return getDataTable(list);
	}
	
	/**
	 * 获取吊车列详细信息
	 */
	@GetMapping(value = "getInfoOpen/{id}")
	public AjaxResult getInfoOpen(@PathVariable("id") Long id) {
		return success(carInfoDetailService.selectCarInfoDetailById(id));
	}

}
